/*
 *  $TEAM_NAME Space Trader
 */
package models;

import java.util.Collection;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;

/**
 * TradeGood container
 * @author twb
 * @version 1.0
 */
public class TradeGood {
	
	/**
	 * 5
	 */
	private static final int FIVE = 5;
	
	/**
	 * 10
	 */
	private static final int TEN = 10;
	
	/**
	 * Goods
	 */
	private static final Map<String, TradeGood> TRADE_GOOD_ZYGOTE = 
			new HashMap<String, TradeGood>();
	
	/**
	 * fur tradegood
	 */
	public static final TradeGood FUR = new TradeGood("Fur", 
    		0, 0, 0, 250, 10, 10, "COLD", "RICHFAUNA", "LIFELESS", 230, 280);
	
	/**
	 * food tradegood
	 */
	private static final TradeGood FOOD = new TradeGood("Food", 
    		1, 0, 1, 100, 5, 5, "CROPFAIL", "RICHSOIL", "POORSOIL", 90, 160);
	
	/**
	 * ore tradegood
	 */
	private static final TradeGood ORE = new TradeGood("Ore", 
    		2, 2, 3, 350, 20, 10, "WAR", "MINERALRICH", "MINERALPOOR", 350, 420);
	
	/**
	 * game tradegood
	 */
	private static final TradeGood GAME = new TradeGood("Game", 
    		3, 1, 6, 250, -10, 5, "BOREDOM", "ARTISTIC", null, 160, 270);
	
	/**
	 * firearm tradegood
	 */
	private static final TradeGood FIREARM = new TradeGood("Firearm", 
    		3, 1, 5, 1250, -75, -1, "WAR", "WARLIKE", null, 600, 1100);
	
	/**
	 * medicine tradegood
	 */
	private static final TradeGood MEDICINE = new TradeGood("Medicine", 
    		4, 1, 6, 650, -20, 10, "PLAGUE", "LOTSOFHERBS", null, 400, 700);
	
	/**
	 * machine tradegood
	 */
	private static final TradeGood MACHINE = new TradeGood("Machine", 
    		4, 3, 5, 900, -30, 5, "LACKOFWORKERS", null, null, 600, 800);
	
	/**
	 * narcotic tradegood
	 */
	private static final TradeGood NARCOTIC = new TradeGood("Narcotic", 
    		5, 0, 5, 3500, -125, 150, "BOREDOM", "WEIRDMUSHROOMS", null, 2000, 3000);
	
	/**
	 * robot tradegood
	 */
	private static final TradeGood ROBOT = new TradeGood("Robot", 
    		6, 4, 7, 5000, -150, 100, "LACKOFWORKERS", null, null, 3500, 5000);
	
	static {
		TRADE_GOOD_ZYGOTE.put("Fur", FUR);
		TRADE_GOOD_ZYGOTE.put("Food", FOOD);
		TRADE_GOOD_ZYGOTE.put("Ore", ORE);
		TRADE_GOOD_ZYGOTE.put("Game", GAME);
        TRADE_GOOD_ZYGOTE.put("Firearm", FIREARM);
        TRADE_GOOD_ZYGOTE.put("Medicine", MEDICINE);
        TRADE_GOOD_ZYGOTE.put("Machine", MACHINE);
        TRADE_GOOD_ZYGOTE.put("Narcotic", NARCOTIC);
        TRADE_GOOD_ZYGOTE.put("Robot", ROBOT);
	}
    
	/**
	 * Random number generator
	 */
	private static Random Rng = new Random();

	/**
	 * name of the good
	 */
	private String name;
	
	/**
	 * mtlp setting
	 */
	private int mtlp;
	
	/**
	 * mtlu setting
	 */
	private int mtlu;
	
	/**
	 * ttp setting
	 */
	private int ttp;
	
	/**
	 * basePrice of the good
	 */
	private int basePrice;
	
	/**
	 * ipl setting
	 */
	private int ipl;
	
	/**
	 * var setting
	 */
	private int var;
	
	/**
	 * ie setting
	 */
	private String ie;
	
	/**
	 * cr setting
	 */
	private String cr;
	
	/**
	 * er setting
	 */
	private String er;
	
	/**
	 * mtl setting
	 */
	private int mtl;
	
	/**
	 * mth setting
	 */
	private int mth;
	
	/**
	 * Create new tradegood
	 * @param name
	 * @param mtlp
	 * @param mtlu
	 * @param ttp
	 * @param basePrice
	 * @param ipl
	 * @param var
	 * @param ie
	 * @param cr
	 * @param er
	 * @param mtl
	 * @param mth
	 */
	private TradeGood(String name, int mtlp, int mtlu, 
			int ttp, int basePrice, int ipl, int var, String ie, 
			String cr, String er, int mtl, int mth) {
		this.name = name;
		this.mtlp = mtlp;
		this.mtlu = mtlu;
		this.ttp = ttp;
		this.basePrice = basePrice;
		this.ipl = ipl;
		this.var = var;
		this.ie = ie;
		this.cr = cr;
		this.er = er;
		this.mtl = mtl;
		this.mth = mth;
	}

	/**
	 * Get name of goods
	 * @return names
	 */
    public static Set<String> getTradeGoodNames() {
        return TRADE_GOOD_ZYGOTE.keySet();
    }

    /**
     * Get collection of goods
     * @return the collection
     */
    public static Collection<TradeGood> getTradeGoods() {
        return TRADE_GOOD_ZYGOTE.values();
    }

    /**
     * Get the price of the good
     * @param s
     * @return the price
     */
    public int getPrice(StarSystem s) {
        return (this.basePrice 
        		+ (this.ipl * (s.getTechLevel().ordinal() + 1 - this.mtlp)) 
        		+ (this.var)) 
        		+ Rng.nextInt(TEN);
    }

    /**
     * Get the quantity
     * @param s
     * @return the quantity
     */
    public int getQuantity(StarSystem s) {
    	if (mtlp <= s.techLevel.ordinal()) {
    		return FIVE + Rng.nextInt(TEN);
    	} else {
    		return 0;
    	}
    }

    /**
     * gets the name
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * to string
     * @return string
     */
    public String toString() {
        return getName();
    }

	/**
	 * @return the rng
	 */
	public static Random getRng() {
		return Rng;
	}

	/**
	 * @param rng the rng to set
	 */
	public static void setRng(Random rng) {
		TradeGood.Rng = rng;
	}

	/**
	 * @return the mTLP
	 */
	public int getMTLP() {
		return mtlp;
	}

	/**
	 * @param mTLP the mTLP to set
	 */
	public void setMTLP(int mTLP) {
		mtlp = mTLP;
	}

	/**
	 * @return the mTLU
	 */
	public int getMTLU() {
		return mtlu;
	}

	/**
	 * @param mTLU the mTLU to set
	 */
	public void setMTLU(int mTLU) {
		mtlu = mTLU;
	}

	/**
	 * @return the tTP
	 */
	public int getTTP() {
		return ttp;
	}

	/**
	 * @param tTP the tTP to set
	 */
	public void setTTP(int tTP) {
		ttp = tTP;
	}

	/**
	 * @return the basePrice
	 */
	public int getBasePrice() {
		return basePrice;
	}

	/**
	 * @param basePrice the basePrice to set
	 */
	public void setBasePrice(int basePrice) {
		this.basePrice = basePrice;
	}

	/**
	 * @return the iPL
	 */
	public int getIPL() {
		return ipl;
	}

	/**
	 * @param iPL the iPL to set
	 */
	public void setIPL(int iPL) {
		ipl = iPL;
	}

	/**
	 * @return the var
	 */
	public int getVar() {
		return var;
	}

	/**
	 * @param var the var to set
	 */
	public void setVar(int var) {
		this.var = var;
	}

	/**
	 * @return the iE
	 */
	public String getIE() {
		return ie;
	}

	/**
	 * @param iE the iE to set
	 */
	public void setIE(String iE) {
		ie = iE;
	}

	/**
	 * @return the cR
	 */
	public String getCR() {
		return cr;
	}

	/**
	 * @param cR the cR to set
	 */
	public void setCR(String cR) {
		cr = cR;
	}

	/**
	 * @return the eR
	 */
	public String getER() {
		return er;
	}

	/**
	 * @param eR the eR to set
	 */
	public void setER(String eR) {
		er = eR;
	}

	/**
	 * @return the mTL
	 */
	public int getMTL() {
		return mtl;
	}

	/**
	 * @param mTL the mTL to set
	 */
	public void setMTL(int mTL) {
		mtl = mTL;
	}

	/**
	 * @return the mTH
	 */
	public int getMTH() {
		return mth;
	}

	/**
	 * @param mTH the mTH to set
	 */
	public void setMTH(int mTH) {
		mth = mTH;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
}
